package com.dgw.springbootmail.controller;

import com.dgw.springbootmail.listener.OnlinePersonListener;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.UUID;

@RestController
public class TestController {

    @GetMapping("/addSession")
    public String addSession(HttpServletRequest request) {
        HttpSession session = request.getSession();
        session.setAttribute("name"+ UUID.randomUUID(), "dgw");
        return "当前在线人数" + OnlinePersonListener.onlinePeople;
    }

    @GetMapping("/removeSession")
    public String removeSession(HttpServletRequest request) {
        HttpSession session = request.getSession();
        session.invalidate();
        return "当前在线人数" + OnlinePersonListener.onlinePeople;
    }

    @GetMapping("/online")
    public String online() {
        return "当前在线人数：" + OnlinePersonListener.onlinePeople + "人";
    }
}
